/**
 * 
 */
package presentation;

import java.util.Collection;

import javax.swing.table.AbstractTableModel;

import user.ClientDTO;

public class ClientDTOTableModel extends AbstractTableModel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Collection<ClientDTO> data;
	private String[] columnNames = {"Nom","Prenom","Date de Naissance"};
	
	/**
	 * @param data
	 */
	public ClientDTOTableModel(Collection<ClientDTO> data) {
		setCollection(data);
	}
	
	public int getColumnCount() {
		return columnNames.length;
	}
	
	public int getRowCount() {
		if(this.data == null){
			return 0;
		}
		else{
			return this.data.size();
		}
	}
	
	public Object getValueAt(int rowIndex, int columnIndex) {
		ClientDTO cli = (ClientDTO) data.toArray()[rowIndex];
		switch (columnIndex){
		case 0 : return cli.getNom_Cli();
		case 1 : return cli.getPrenom_Cli();
		case 2 : return cli.getDateNaiss_Cli();
		default : throw new IllegalArgumentException("Colonne Inconnue"+columnIndex);
		}
	}
	
	public ClientDTO getClientAt(int rowIndex){
		ClientDTO cli = (ClientDTO) data.toArray()[rowIndex];
		return cli;
	}
	
	public boolean isCellEditable(int arg0, int arg1) {
		return false;
	}
	
	public String getColumnName(int column) {
		return this.columnNames[column];
	}
	
	public Class<?> getColumnClass(int columnIndex) {
		if(data==null) return Object.class;
		else{
			Object objetRecupere = getValueAt(0, columnIndex);
			if(objetRecupere==null) return Object.class;
			else return objetRecupere.getClass();
		}
	}
	
	public void setCollection(Collection<ClientDTO> coll){
		this.data = coll;
		fireTableDataChanged();
	}
}
